﻿package fui.FUIComponents{
	import flash.events.*;
	import flash.display.Sprite;
	import fl.controls.*;
	import fl.containers.ScrollPane;
	import flash.text.TextFormat;
	import fl.data.DataProvider;
	import fl.controls.DataGrid;
	import fl.controls.dataGridClasses.DataGridColumn;

	import fui.FUIControllers.*;
	
	public class GamesList extends Sprite implements IComponent{
		private var _comName:String = "";
		private var _uis:UISession;
		private var _titlearr:Array = new Array("Creator","Start date","Max players", "private/public", "game category");
		private var _lablarr:Array;
		var rcView:FUIRecordView;
		
		public function GamesList()
		{
			this._comName = "Registered Games";
			//testGrid();
//			createView();
		}
		public function testGrid():void
		{
			var arr:Array = [{col1:"1.A", col2:"1.B"}, {col1:"2.A", col2:"2.B"}];
			trace("-----\nData provider creation\n---------------\n");
			var dp:DataProvider = new DataProvider();
			trace("dp " + dp);
			dp.addItems(arr);
			trace(dp.length); // 2

			var c1:DataGridColumn = new DataGridColumn("col1");
			var c2:DataGridColumn = new DataGridColumn("col2");
	
			var myDataGrid:DataGrid = new DataGrid();
			trace("new datagrid creeated");
			myDataGrid.addColumn(c1);
			myDataGrid.addColumn(c2);
			myDataGrid.dataProvider = dp;
			myDataGrid.setSize(200, 160);
			myDataGrid.move(10, 10);
			addChild(myDataGrid);
			trace("Grid added" );
		}
		private function setTitles():void
		{
			_lablarr = new Array();
			for ( var i=0; i < _titlearr.length; i++)
			{
				_lablarr[i] = new Label();
				_lablarr[i].text = _titlearr[i];
				_lablarr[i].x = i*80 + 20;
				_lablarr[i].y = 20;
				_lablarr[i].width = 80;
				addChild(_lablarr[i]);
			}
		}
		private function createView():void
		{
			setTitles();
			rcView = new FUIRecordView(5, 20, 40, 80);
			addChild(rcView);
			
		}
		private function loadData():void
		{
			var creators:DataProvider = new DataProvider();
			var startDate:DataProvider = new DataProvider();
			var maxPlayers:DataProvider = new DataProvider();
			var private_public:DataProvider = new DataProvider();
			var category:DataProvider = new DataProvider();
			var dparr:Object = new Object();
			//creators.addItems({item:"Dalt"},{item:"Borel"},{item:"Tomer"});
			dparr.p0 = creators;
			dparr.p1 = startDate;
			dparr.p2 = maxPlayers;
			dparr.p3 = private_public;
			dparr.p4 = category;
			rcView.setData(dparr);
		}
		public function set_xml_source(xml_path:String):void
		{
		}
		public function set_session(uis:UISession):void
		{
			this._uis = uis;
		}
		public function get_component_title():String
		{
			return this._comName;
		}
        public function show_component():void
		{
			//TODO:
			visible = true;
		}
		
		public function hide_component():void
		{
			//TODO:
			visible = false;
		}
		public function if_need_auth():Boolean
		{
			//TODO:
			return false;
		}
		public function self_remove():void
		{
			//TODO:
		}
		public function startCreatedGame():void
		{
			// here should run up Game instanse //TODO to Tomer
		}
	}
}